import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

x = np.linspace(-20, 20, 1000)
# 画子图
## 第一种（推荐）
plt.figure(figsize=(3 * 5, 5))
axes1 = plt.subplot(1, 3, 1)
# axes1 = plt.subplot(131)  # 同上，不推荐
axes1.plot(x, np.sin(x))
axes1.grid(lw=2)

axes2 = plt.subplot(1, 3, 2)
axes2.plot(x, np.cos(x))
axes2.grid(c='r', alpha=0.6)

axes3 = plt.subplot(1, 3, 3)
axes3.plot(x, x ** 2)
axes3.grid(c='g', ls='--', alpha=0.6)
plt.show()

## 第二种
figure = plt.figure(figsize=(3 * 5, 5))
axes1 = figure.add_subplot(1, 3, 1)
axes1.plot(x, np.sin(x))
axes1.grid(lw=2)

axes2 = figure.add_subplot(1, 3, 2)
axes2.plot(x, np.cos(x))
axes2.grid(c='r', alpha=0.6)

axes3 = figure.add_subplot(1, 3, 3)
axes3.plot(x, x ** 2)
axes3.grid(c='g', ls='--', alpha=0.6)
plt.show()
